﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TaleWorlds.CampaignSystem;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.GameComponents;
using TaleWorlds.Core;
using TaleWorlds.Localization;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Library;

//改变俘虏数量
namespace ExampleMod
{

    public class CustomPartySizeLimitModel : DefaultPartySizeLimitModel
    {
        //读取某个初值,不知道干啥的,先放这
        private readonly TextObject _baseSizeText = GameTexts.FindText("str_base_size", null);
        //不知道干啥的,后边用到了,放这
        private readonly TextObject _wallLevelBonusText = GameTexts.FindText("str_map_tooltip_wall_level", null);

        //自定义的移动时部队携带的俘虏计算规则
        private ExplainedNumber CalculateMobilePartyPrisonerSizeLimitInternal(PartyBase party, bool includeDescriptions = false)
        {
            ExplainedNumber result = new ExplainedNumber(10f, includeDescriptions, this._baseSizeText);
            result.Add(5000f, new TextObject("{=!}特大号囚车!", null), null);
            return result;
        }

        //自定义的,城堡里俘虏计算规则
        private ExplainedNumber CalculateSettlementPartyPrisonerSizeLimitInternal(Settlement settlement, bool includeDescriptions = false)
        {
            ExplainedNumber result = new ExplainedNumber(30f, includeDescriptions, this._baseSizeText);
            Town town = settlement.Town;
            int num = (town != null) ? town.GetWallLevel() : 0;
            if (num > 0)
            {
                result.Add((float)(num * 10), this._wallLevelBonusText, null);
            }
            return result;
        }

        //覆写的父类的获取俘虏上限方法
        public override ExplainedNumber GetPartyPrisonerSizeLimit(PartyBase party, bool includeDescriptions = false)
        {
            bool isMainHero = party.LeaderHero != null && party.LeaderHero == Hero.MainHero ;
            //如果是玩家的部队,就指向子类自定义俘虏计算
            if (isMainHero)
            {
                return this.CalculateMobilePartyPrisonerSizeLimitInternal(party, includeDescriptions);
            }
            return base.GetPartyPrisonerSizeLimit(party, includeDescriptions);
        }


    }
}
